package com.design.alex.flyweight;

/**
 * @ClassName : FlyweightPatternDemo
 * @Description : todo
 * @Author : Alex
 * @Date: 2020-02-17 17:33
 */
public class FlyweightPatternDemo {
    private static final String colors[] = {"Red", "Green", "Blue", "White", "Black"};
    public static void main(String[] args) {

        for(int i=0; i < 20; ++i) {
            String color = getRandomColor();
            Circle circle =
                    (Circle)ShapeFactory.getCircle(color);
            circle.setColor(color);
            circle.setX(getRandomX());
            circle.setY(getRandomY());
            circle.setRadius(100 + i);
            circle.draw();
        }
    }
    private static String getRandomColor() {
        return colors[(int)(Math.random()*colors.length)];
    }
    private static int getRandomX() {
        return (int)(Math.random()*100 );
    }
    private static int getRandomY() {
        return (int)(Math.random()*100);
    }
}
